package com.xinchengxd.goods.mapper;


import com.xinchengxd.commons.entity.dto.GoodsNums;
import com.xinchengxd.commons.entity.goods.Category;
import com.xinchengxd.commons.entity.goods.Goods;
import com.xinchengxd.commons.entity.goods.ShoppingCart;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GoodsMapper {
    @Select("select * from mall_goods limit #{number}")
//    @Results({
//            @Result(column = "category_id",property = "category",
//            One = @One(select = "com.xinchengxd.order.goods.mapper.GoodsMapper.getCategory")
//            )
//    })
    List<Goods> limit(Integer number);

    @Select("select * from mall_goods where id = #{id}")
    Goods findById(Integer id);

    @Update("update mall_goods set stock = #{num} where id = #{id}")
    int stock(Integer num,Integer id);

    @Select("select * from mall_category where id = #{id}")
    Category getCategory(@Param("category") Integer category);

    List<Goods> findByList(List<GoodsNums> item);


    @Select("select a.id as id,a.user_id as userID,a.goods_id as goodsId,b.name as goodsName,a.nums as nums,a.status as status " +
            "from mall_shopping_cart as a " +
            "left join mall_goods as b on a.goods_id = b.id where user_id = #{userId}")
    List<ShoppingCart> findCart(Integer userId);
}
